from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
import json


def send_sms(phone_numbers, sign_name, template_code, message):
    with open('config.json', 'r') as file:
        config = json.load(file)

    client = AcsClient(config["sms"]["access_key_id"], config["sms"]["access_key_secret"], 'cn-hangzhou')
    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')  # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')
    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers', phone_numbers)
    request.add_query_param('SignName', sign_name)
    request.add_query_param('TemplateCode', template_code)
    request.add_query_param('TemplateParam', json.dumps(message))
    response = client.do_action_with_exception(request)
    print(str(response, encoding='utf-8'))
